local tianjie = fk.CreateSkill {

  name = "joy__tianjie",

  tags = {  },

}



tianjie:addEffect(fk.TurnEnd, {
  name = "joy__tianjie",
  anim_type = "offensive",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(tianjie.name) then
      if player:getMark(tianjie.name) > 0 then
        player.room:setPlayerMark(player, tianjie.name, 0)
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false), Util.IdMapper), 1, 3, "#joy__tianjie-choose", tianjie.name, true)
    if #tos > 0 then
      event:setCostData(self, tos)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(event:getCostData(self)) do
      local p = room:getPlayerById(id)
      local n = math.max(1, #table.filter(p.player_cards[Player.Hand], function(c) return Fk:getCardById(c).name == "jink" end))
      room:damage{
        from = player,
        to = p,
        damage = n,
        damageType = fk.ThunderDamage,
        skillName = tianjie.name,
      }
    end
  end,
})
tianjie:addEffect(fk.AfterDrawPileShuffle, {
  refresh_events = {fk.AfterDrawPileShuffle},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self, true)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, tianjie.name, 1)
  end,
})

return tianjie